<?php
class M_report extends CI_Model{

	function getdata(){
		   $sql = "select DAY(pengunjung_waktu) tanggal, count(pengunjung_id) pengunjung ";
            $sql_loket = "SELECT * FROM m_loket ";
            $query_loket = $this->db->query($sql_loket);
            $result_loket =  $query_loket->result();
            foreach($result_loket as $row_loket){
                $sql .= " , sum(if(m_loket_id = $row_loket->loket_id ,1,0)) loket_$row_loket->loket_id ";
            }
            $sql .= " from t_pengunjung left join m_loket on m_loket_id = loket_id
where loket_active = 1 AND MONTH(pengunjung_waktu) = MONTH(NOW()) AND YEAR(pengunjung_waktu) = YEAR(NOW()) 
group by DAY(pengunjung_waktu)";
            $query = $this->db->query($sql);
            $result = $query->result_array();
            $data = array();
            foreach( $result  as $row){
                $loket = array();
                 foreach($result_loket as $row_loket){
                    $loket[$row_loket->loket_id] = $row["loket_".$row_loket->loket_id];
                 }
                $data[$row["tanggal"]] = array(
                    "jml" => $row["pengunjung"],
                    "loket" => $loket
                );
            }
        
        /*    $last_day = date("t");
            $return = array();
            for($i=1; $i<= $last_day; $i++){
                $jumlah = (@$data[$i] == "")? 0 : @$data[$i];
                $return[] = array(
                    "tgl" => $i,
                    "loket" => $loket
                    "jml" => $jumlah  
                );
            } */
            return $data;
    }
}
	